package com.heima.admin.service.impl;

import com.heima.admin.service.AdminWmNewsService;
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.pojos.WmNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author HNCheng
 * @version 1.0
 * @since 2023/8/2 14:41
 */
@Service
public class AdminWmNewsServiceImpl implements AdminWmNewsService {

    @Autowired
    private IWemediaClient wemediaClient;
    /**
     * 查询文章列表
     * @param newsAuthDto
     * @return
     */
    @Override
    public ResponseResult listVo(NewsAuthDto newsAuthDto) {
        return wemediaClient.listVo(newsAuthDto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @Override
    public ResponseResult wmNewsInfo(Integer id) {
        return wemediaClient.wmNewsInfo(id);
    }

    /**
     * 更新文章审核状态 2:审核失败 4:审核成功
     * @param newsAuthDto
     * @return
     */
    @Override
    public ResponseResult updateStatus(NewsAuthDto newsAuthDto) {
        if (newsAuthDto.getStatus().equals(WmNews.Status.FAIL.getCode())) {
            return wemediaClient.authFail(newsAuthDto);
        } else if (newsAuthDto.getStatus().equals(WmNews.Status.ADMIN_SUCCESS.getCode())) {
            return wemediaClient.authPass(newsAuthDto);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
}
